package blackithei.TCP;

import java.io.*;
import java.net.Socket;

//TCP 传输数据及返回数据(字符串)
public class ClientDemo1 {
    public static void main(String[] args) throws IOException {
        //创建Socket对象
        Socket so=new Socket("127.0.1",10001);
        //创建字符缓冲输出流  转换流
        BufferedWriter bf=new BufferedWriter(new OutputStreamWriter(so.getOutputStream()));
        //写数据
        bf.write("大漠孤烟直");
        //刷新流
        bf.flush();
        //暂时关闭
        so.shutdownOutput();

        //接收反馈
        //创建字符缓冲输入流
        BufferedReader buff=new BufferedReader(new InputStreamReader(so.getInputStream()));
        //读取数据
        String line;
        while((line=buff.readLine())!=null){
            System.out.println(line);
        }

        buff.close();
        bf.close();
        so.close();

    }
}
